package ua.tach.shortl.screens;

import ua.tach.shortl.Renderer;
import ua.tach.shortl.Input;
import ua.tach.shortl.logic.Country;

import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;

public class GameLoop implements Screen {
	private final Renderer renderer;
	private final Input input;
	/** is done flag **/
	private boolean isDone = false;

	public GameLoop (Application app) {
		renderer = new Renderer(app);
		input = new Input();
		Gdx.input.setInputProcessor(input);
		Country.gamePause = true; // -----------------------------------!!!!!!!!!!!!!!!!!!!!
	}

	@Override public void dispose () {
		renderer.dispose();
	}

	@Override public boolean isDone () {
		return isDone;
	}

	@Override public void render (Application app) {
		//app.getGraphics().getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
		renderer.render(app);
	}

	@Override public void update (Application app) {
		Country.update(app.getGraphics().getDeltaTime());

		if (!input.handled) {
			Country.setvect(input.vector);
		}
		if (input.key != 0) {
			System.out.println("Key down "+ input.key);
			switch (input.key) {
			case 31: // c - build new city
				Country.addCity();
				break;
			case 41: // m - menu
				Country.gamePause = true;
				break;
			case 48: // t - train
				Country.startTrain();
				break;
			default:
			}
		}

		input.tick();

/*		if (input.isKeyPressed(Keys.KEYCODE_DPAD_LEFT)) simulation.moveShipLeft(app.getGraphics().getDeltaTime(), 0.5f);
		if (input.isKeyPressed(Keys.KEYCODE_DPAD_RIGHT)) simulation.moveShipRight(app.getGraphics().getDeltaTime(), 0.5f);

		if (input.isTouched() || input.isKeyPressed(Keys.KEYCODE_SPACE)) simulation.shot();*/
	}

}
